  <template>
  <!-- <el-scrollbar style="height: calc(100vh + 27px);"> -->
  <div>
    <el-form :inline="true" label-width="100px" :model="form" ref="form" :rules="rules">
      <el-row>
        <p>客户信息</p>
        <el-col :span="3.5">
          <el-form-item label="客户姓名:" prop="customerName">
            <el-input :size="size" v-model="form.customerName" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="联系电话:" prop="phone">
            <el-input :size="size" v-model="form.phone" @blur="phonecx" @clear="phoneClear" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="身份证号码:" prop="idCard">
            <el-input :size="size" v-model="form.idCard" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="性别:" prop="customerSex">
            <el-select v-model="form.customerSex" placeholder="请选择" :size="size" clearable>
              <el-option v-for="item in sex" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="客户职业:" prop="customerZhiwei">
            <el-input :size="size" v-model="form.customerZhiwei" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="区域:" prop="area">
            <el-select :size="size" v-model="form.area" placeholder="请选择区域" clearable>
              <el-option v-for="item in area" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="订车日期:" prop="dingDate">
            <el-date-picker :size="size" v-model="form.dingDate" type="date" placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="交车日期:" prop="jiaoDate">
            <el-date-picker :size="size" @change="jiaoDateChange" v-model="jiaoDate.jiaoDate" type="date"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="转介绍:" prop="zhuanjieshao">
            <el-select v-model="form.zhuanjieshao" placeholder="请选择" :size="size" clearable>
              <el-option v-for="item in zhuanjieshao1" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="发票号码:" prop="faPiaoNum">
            <el-input :size="size" v-model="form.faPiaoNum" clearable></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="3.5">
          <el-form-item label="发动机号:" prop="faDongJi">
            <el-input :size="size" v-model="form.faDongJi" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="车架号:" prop="cheJia">
            <el-input :size="size" v-model="form.cheJia" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <!-- 车型 -->
          <el-form-item v-if="!ershou" label="车型:" prop="cars">
            <el-select :size="size" v-model="form.cars" placeholder="请选择车型" clearable>
              <el-option v-for="item in cars" :key="item.value" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item v-if="ershou"  label="车型:" prop="cars">
            <el-select :size="size" v-model="form.cars2" placeholder="请选择车型" clearable>
              <el-option v-for="item in cars" :key="item.value" :label="item.esccxmc" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="合同编号:" prop="contractNO">
            <el-input :size="size" v-model="form.contractNO" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="颜色:" prop="color">
            <el-input :size="size" v-model="form.color" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="合格证号码:" prop="heGeZhengNum">
            <el-input :size="size" v-model="form.heGeZhengNum" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="销售价格:" prop="xiaoShouPrice">
            <el-input :size="size" v-model="form.xiaoShouPrice" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="部门:" prop="dept">
            <el-input :size="size" v-model="form.dept" disabled clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="职位:" prop="zhiwei">
            <el-input :size="size" v-model="form.zhiwei" disabled clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="订交人员:" prop="name">
            <el-input :size="size" v-model="form.name" disabled clearable></el-input>
          </el-form-item>
        </el-col>

      </el-row>
      <el-row>
        <p>赠送项目</p>
        <el-col :span="3.5">
          <el-form-item label="精品名称:" prop="zengJingPin">
            <el-select v-model="form.zengJingPin" placeholder="请选择" :size="size" multiple collapse-tags clearable>
              <el-option v-for="item in zengJingPin1" :key="item.value" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="保养套餐:" prop="zengBaoYang">
            <el-select v-model="form.zengBaoYang" placeholder="请选择" :size="size" multiple collapse-tags clearable>
              <el-option v-for="item in zengBaoYang1" :key="item.value" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="延保名称:" prop="zengYanBao">
            <el-select v-model="form.zengYanBao" placeholder="请选择" :size="size" multiple collapse-tags clearable>
              <el-option v-for="item in zengYanBao1" :key="item.value" :label="item.name" :value="item.id"> </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="洗美名称:" prop="zengXiMei">
            <el-select v-model="form.zengXiMei" placeholder="请选择" :size="size" multiple collapse-tags clearable>
              <el-option v-for="item in zengXiMei1" :key="item.value" :label="item.name" :value="item.id"> </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="18">
          <el-form-item label="保险公司:" prop="zengBaoXian">
            <el-select @change="zengbaoxian" v-model="form.zengBaoXian" placeholder="请选择" :size="size" clearable>
              <el-option v-for="item in zengBaoXian1" :key="item.value" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="交强险" prop="zengJiaoQiangXian">
            <el-input-number :size="size" controls-position="right" :disabled="!form.zengBaoXian" :step="0.1" :min="0"
              :precision="2" v-model="form.zengJiaoQiang"> </el-input-number>
          </el-form-item>
          <el-form-item label="商业险" prop="zengShangYeXian">
            <el-input-number :size="size" controls-position="right" :disabled="!form.zengBaoXian" :step="0.1" :min="0"
              :precision="2" v-model="form.zengShangYeXian"> </el-input-number>
          </el-form-item>
        </el-col>

        <el-col :span="18">
          <el-form-item label="金融公司:" prop="zengJinRong">
            <el-select @change="zengjinrong" v-model="form.zengJinRong" placeholder="请选择" :size="size" clearable>
              <el-option v-for="item in zengJinRong1" :key="item.value" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="zengSongJinRongMoney">
            <el-input-number :size="size" controls-position="right" :disabled="!form.zengJinRong" :step="0.1" :min="0"
              :precision="2" v-model="form.zengSongJinRongMoney"> </el-input-number>
          </el-form-item>

          <el-form-item label="车牌公司:" prop="zengChePai">
            <el-select @change="zengchepai" v-model="form.zengChePai" placeholder="请选择" :size="size" clearable>
              <el-option v-for="item in zengChePai" :key="item.value" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="zengSongChePai">
            <el-input-number :size="size" controls-position="right" :disabled="!form.zengChePai" :step="0.1" :min="0"
              :precision="2" v-model="form.zengSongChePai"> </el-input-number>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <p style="margin-top: 1px;">销售项目</p>
        <el-col :span="3.5">
          <el-form-item label="精品名称:" prop="maiJingPin">
            <el-select v-model="form.maiJingPin" placeholder="请选择" :size="size" multiple collapse-tags clearable>
              <el-option v-for="item in zengJingPin1" :key="item.value" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="保养套餐:" prop="maiBaoYang">
            <el-select v-model="form.maiBaoYang" placeholder="请选择" :size="size" multiple collapse-tags clearable>
              <el-option v-for="item in zengBaoYang1" :key="item.value" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="延保名称:" prop="maiYanBao">
            <el-select v-model="form.maiYanBao" placeholder="请选择" :size="size" multiple collapse-tags clearable>
              <el-option v-for="item in zengYanBao1" :key="item.value" :label="item.name" :value="item.id"> </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="3.5">
          <el-form-item label="洗美名称:" prop="maiXiMei">
            <el-select v-model="form.maiXiMei" placeholder="请选择" :size="size" multiple collapse-tags clearable>
              <el-option v-for="item in zengXiMei1" :key="item.value" :label="item.name" :value="item.id"> </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="18">
          <el-form-item label="保险公司:" prop="maiBaoXian">
            <el-select @change="maibaoxian" v-model="form.maiBaoXian" placeholder="请选择" :size="size" clearable>
              <el-option v-for="item in zengBaoXian1" :key="item.value" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="交强险" prop="maiJiaoQiangXian">
            <el-input-number :size="size" controls-position="right" :disabled="!form.maiBaoXian" :step="0.1" :min="0"
              :precision="2" v-model="form.maiJiaoQiang"> </el-input-number>
          </el-form-item>
          <el-form-item label="商业险" prop="maiShangYeXian">
            <el-input-number :size="size" controls-position="right" :disabled="!form.maiBaoXian" :step="0.1" :min="0"
              :precision="2" v-model="form.maiShangYeXian"> </el-input-number>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item label="金融公司:" prop="maiJinRong">
            <el-select @change="maijinrong" v-model="form.maiJinRong" placeholder="请选择" :size="size" clearable>
              <el-option v-for="item in zengJinRong1" :key="item.value" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="xiaoShouJinRongMoney">
            <el-input-number :size="size" :disabled="!form.maiJinRong" controls-position="right" :step="0.1" :min="0"
              :precision="2" v-model="form.xiaoShouJinRongMoney"> </el-input-number>
          </el-form-item>
          <el-form-item label="车牌公司:" prop="maiChePai">
            <el-select @change="maichepai" v-model="form.maiChePai" placeholder="请选择" :size="size" clearable>
              <el-option v-for="item in zengChePai" :key="item.value" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="xiaoShouChePai">
            <el-input-number :size="size" controls-position="right" :disabled="!form.maiChePai" :step="0.1" :min="0"
              :precision="2" v-model="form.xiaoShouChePai"> </el-input-number>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <el-form-item label="二手车公司:" prop="twoCompanyName">
            <el-select v-model="form.twoCompanyName" placeholder="请选择" :size="size" clearable @change="aaa3">
              <el-option v-for="item in twoCompanyName1" :key="item.value" :label="item.name" :value="item.name">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="xiaoShouJinRongMoney">
            <el-input-number :size="size" controls-position="right" :disabled="!form.twoCompanyName" :step="0.1"
              :min="0" :precision="2" v-model="form.twoCompanyPrice"> </el-input-number>
          </el-form-item>

          <el-popconfirm
          style="float: right; margin-right: 10px;"
            title="确定信息都正确？"
            @confirm="save()"
          >
            <el-button type="success" slot="reference">提交</el-button>
          </el-popconfirm>
          <el-popconfirm
          style="float: right; margin-right: 10px;"
            title="确定要清空所有内容吗？"
            @confirm="qingkong()"
          >
            <el-button  type="success"   @click="uplod" >批量提交</el-button>
            <el-button type="warning" slot="reference">清空</el-button>
          </el-popconfirm>
          <el-dialog title="上传文件" :visible.sync="dialogVisible" width="31%" >
                <el-form :model="form" :rules="rules" ref="form1" label-width="100px" >
                  <el-form-item class=""  label="">
                    <el-upload :auto-upload="false" :file-list="uploadlist"	  ref="upload" :limit="limitNum"    drag action="qwer" :before-upload="beforeupload" :on-change="fileChange">
                      <i class="el-icon-upload"></i>
                      <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                      <div slot="tip" class="el-upload__tip">只能上传xlsx/xls文件</div>
                    </el-upload>
                  </el-form-item>
                </el-form>
                <span slot="footer" class="dialog-footer">
                  <el-button @click="qx">取 消</el-button>
                  <el-button type="primary" @click="save1" :disabled="saveBtnDisable">保存</el-button>
                </span>
           </el-dialog>
        </el-col>

      </el-row>

    </el-form>
  </div>
  <!-- </el-scrollbar> -->
</template>

<script>
  export default {

    data() {
      return {
        dialogVisible: false,
        form1: {
        },
        param: {
          file: '',
        },
        saveBtnDisable: false,
        file2:null,
        limitNum: 1,  // 上传excell时，同时允许上传的最大数
        fileList:[],
        uploadlist:[],

        ershou:false,
        size: 'small',
        form: {
          xiaoShouChePai: 0,
          zengSongChePai: 0,
          maiChePai: '',
          zengChePai: '',
          customerName: '',
          idCard: '',
          customerSex: '',
          area: '',
          phone: '',
          customerZhiwei: '',
          dept: '',
          zhiwei: '',
          name: '',
          zhuanjieshao: '',
          dingDate: '',
          cars: '',
          contractNO: '',
          color: '',
          heGeZhengNum: '',
          faPiaoNum: '',
          faDongJi: '',
          cheJia: '',
          xiaoShouPrice: '',
          zengJingPin: '',
          zengBaoYang: '',
          zengYanBao: '',
          zengXiMei: '',
          zengJinRong: '',
          zengSongJinRongMoney: 0,
          maiJingPin: '',
          maiBaoYang: '',
          maiYanBao: '',
          maiXiMei: '',
          maiJinRong: '',
          xiaoShouJinRongMoney: 0,
          twoCompanyName: '',
          twoCompanyPrice: 0,
          maiJiaoQiang: null,
          maiShangYeXian: null,
          zengJiaoQiang: null,
          zengShangYeXian: null
        },

        jiaoDate: {
          jiaoDate: ''
        },
        sex: [{
          value: '男',
          label: '男'
        }, {
          value: '女',
          label: '女'
        }],
        zengChePai: [],
        zengJingPin1: [],
        zengBaoYang1: [],
        zengYanBao1: [],
        zengXiMei1: [],
        zengBaoXian1: [],
        zengJinRong1: [],
        maiJingPin1: [],
        maiBaoYang1: [],
        maiYanBao1: [],
        maiXiMei1: [],
        maiBaoXian1: [],
        maiJinRong1: [],
        twoCompanyName1: [],
        area: [{
            label: '城区',
            value: '城区'
          },
          {
            label: '城郊',
            value: '城郊'
          },
          {
            label: '区域外',
            value: '区域外'
          }
        ],
        zhuanjieshao1: [{
            label: '是',
            value: '是'
          },
          {
            label: '否',
            value: '否'
          }
        ],
        cars: [],
        rules: {
          customerName: [{
              required: true,
              message: "客户名称不能为空！",
              trigger: "blur"
            },
            {
              validator: function(rule, value, callback) {

                if (/^([a-zA-Z0-9\u4e00-\u9fa5\·]{1,10})$/.test(value) == false) {
                  callback(new Error("真实姓名格式错误,请输入英文或汉字!"));
                } else if (/.*[0-9]{1,}.*/.test(value)) {
                  callback(new Error("真实姓名格式错误,名字不能包含数字!"))
                }
                //校验通过
                callback();
              },
              trigger: "blur"
            }
          ],
          cars: [{
            required: true,
            message: '请选择车型',
            trigger: 'blur'
          }],
          customerSex: [{
            required: true,
            message: '请选择性别',
            trigger: 'blur'
          }],
          area: [{
            required: true,
            message: '请选择区域',
            trigger: 'blur'
          }],
          contractNO: [{
            required: true,
            message: '请输入合同编号',
            trigger: 'blur'
          }],
          color: [{
              required: true,
              message: '请输入颜色',
              trigger: 'blur'
            },

            {
              validator: function(rule, value, callback) {
                //校验中文的正则：/^[\u4e00-\u9fa5]{0,}$/
                if (/^[\u4e00-\u9fa5]+$/.test(value) == false) {
                  callback(new Error("请输入中文"));
                } else {
                  //校验通过
                  callback();
                }
              },
              trigger: "blur"
            }
          ],
          faPiaoNum: [{
            required: true,
            message: '请输入发票号码',
            trigger: 'blur'
          }],
          phone: [{
              required: true,
              message: '请输入联系电话',
              trigger: 'blur'
            },
            {
              validator: function(rule, value, callback) {
                if (/^1[34578]\d{9}$/.test(value) == false) {
                  callback(new Error("手机号格式错误"));
                } else {
                  callback();
                }
              },
              trigger: "blur"
            }
          ],
          zhuanjieshao: [{
            required: true,
            message: '请选择转介绍',
            trigger: 'blur'
          }],
          faDongJi: [{
            required: true,
            message: '请输入发动机号',
            trigger: 'blur'
          }],
          cheJia: [{
            required: true,
            message: '请输入车架号',
            trigger: 'blur'
          }],
          xiaoShouPrice: [{
              required: true,
              message: '请输入销售价格',
              trigger: 'blur'
            },
            {
              validator: function(rule, value, callback) {
                var re = /^\d+$/;
                if (value < 0) {
                  callback(new Error("销售价格不能小于0"));
                } else if (!re.test(value)) {
                  callback(new Error("销售价格只能是数字"));
                }
                callback();
              },
              trigger: "blur"
            }
          ],
          dingDate: [{
            required: true,
            message: '请选择订车日期',
            trigger: 'blur'
          }],
          heGeZhengNum: [{
            required: true,
            message: '请输入合格证号码',
            trigger: 'blur'
          }],
          idCard: [{
              required: true,
              trigger: 'blur',
              message: '请输入身份证',
            },
            {
              validator: function(rule, code, callback) {
                var city = {
                  11: "北京",
                  12: "天津",
                  13: "河北",
                  14: "山西",
                  15: "内蒙古",
                  21: "辽宁",
                  22: "吉林",
                  23: "黑龙江 ",
                  31: "上海",
                  32: "江苏",
                  33: "浙江",
                  34: "安徽",
                  35: "福建",
                  36: "江西",
                  37: "山东",
                  41: "河南",
                  42: "湖北 ",
                  43: "湖南",
                  44: "广东",
                  45: "广西",
                  46: "海南",
                  50: "重庆",
                  51: "四川",
                  52: "贵州",
                  53: "云南",
                  54: "西藏 ",
                  61: "陕西",
                  62: "甘肃",
                  63: "青海",
                  64: "宁夏",
                  65: "新疆",
                  71: "台湾",
                  81: "香港",
                  82: "澳门",
                  91: "国外 "
                };
                var tip = ""
                var pass = true
                if (!code) {
                  return callback()
                }
                if (!/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(code)) {
                  tip = "身份证号格式错误"
                  pass = false;
                } else if (!city[code.substr(0, 2)]) {
                  // tip = "地址编码错误"
                  tip = "身份证输入错误"
                  pass = false
                } else {
                  // 18位身份证需要验证最后一位校验位
                  if (code.length === 18) {
                    code = code.split('')
                    // ∑(ai×Wi)(mod 11)
                    // 加权因子
                    var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
                    // 校验位
                    var parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2]
                    var sum = 0
                    var ai = 0
                    var wi = 0
                    for (var i = 0; i < 17; i++) {
                      ai = code[i]
                      wi = factor[i]
                      sum += ai * wi
                    }
                    var last = parity[sum % 11];
                    if (parity[sum % 11] != code[17]) {
                      // tip = "校验位错误"
                      tip = "身份证输入错误"
                      pass = false
                    }
                  }
                }
                if (!pass) {
                  callback(new Error(tip))
                } else {
                  callback()
                }
              },
              trigger: 'blur'
            }
          ],
        },
      }
    },
    methods: {
      /* ------------上传文件---------- */
      beforeupload(file) {
        this.param.file = file
        /* console.log(this.param) */
        return false;
      },
      fileChange(file, oldFile) {
        let fileType = file.name.substring(file.name.lastIndexOf('.') + 1);
        oldFile = [];
        if (fileType !== 'xlsx' && fileType !== 'xls' ) {
          this.$message.error("文件上传格式不正确");
          return false;
        }
        if (file.size / 1024 / 1024 > 1.5) {
          this.$message.error("文件大小不能超过2M");
          return false;
        }
        this.file = file.raw;
      },

      uplod(){
       /* this.$ajax.post("Excel2/twocompanyIn",{}).then(res =>{

        }) */
        this.param = {};
        emptyObj(this.form);
        this.$emit('show-dialog', this.form);
        this.dialogVisible = true;
      },
      qx(){
        /* console.log(this.$refs.upload); */
        this.dialogVisible=false
        this.$refs.upload.clearFiles()

        this.param.file = ''
        this.fileList = []
      },
      save1(){
        this.$refs.form1.validate(valid => {
          console.log(valid);
          console.log("啦啦啦");
          console.log(this.param.file);
          if (valid) {
            this.$ajax.post("Excel/newCarIn",{'inFile':this.param.file}).then(res=>{
                  console.log("上传成功");
                  this.dialogVisible=false
                  this.param.file = ''
                  this.fileList = []
                  this.$refs.upload.clearFiles()
                }).catch(error => {
                  this.$refs.upload.clearFiles()
                  this.dialogVisible=false
                  this.$notify({
                    title: '提示',
                    message: '上传模板错误',
                    type: 'warning',
                    position: 'bottom-right'
                  });
                 /* console.log("上传模板错误"); */
              })
          }

        })
      },
       /* ---------上传文件----------- */



      zengbaoxian(i) {
        if (i == '') {
          this.form.zengJiaoQiang = 0
          this.form.zengShangYeXian = 0
        }
      },
      maibaoxian(i) {
        if (i == '') {
          this.form.maiJiaoQiang = 0
          this.form.maiShangYeXian = 0
        }
      },
      zengjinrong(i) {
        if (i == '') {
          this.form.zengSongJinRongMoney=0
        }
      },
      zengchepai(i){
        if(i==''){
         this.form.zengSongChePai=0
        }
      },
      maijinrong(i){
        if(i==''){
         this.form.xiaoShouJinRongMoney=0
        }
      },
      maichepai(i){
        console.log(i)
        if(i==''){
         this.form.xiaoShouChePai=0
        }
      },
      qingkong() { //清空
        this.form = {
          maiChePai: '',
          zengChePai: '',
          customerName: '',
          idCard: '',
          customerSex: '',
          area: '',
          phone: '',
          customerZhiwei: '',
          dept: '',
          zhiwei: '',
          name: '',
          zhuanjieshao: '',
          dingDate: '',
          cars: '',
          contractNO: '',
          color: '',
          heGeZhengNum: '',
          faPiaoNum: '',
          faDongJi: '',
          cheJia: '',
          xiaoShouPrice: '',
          zengJingPin: '',
          zengBaoYang: '',
          zengYanBao: '',
          zengXiMei: '',
          zengJinRong: '',
          zengSongJinRongMoney: 0,
          maiJingPin: '',
          maiBaoYang: '',
          maiYanBao: '',
          maiXiMei: '',
          maiJinRong: '',
          xiaoShouJinRongMoney: 0,
          twoCompanyName: '',
          twoCompanyPrice: 0,
          maiJiaoQiang: 0,
          maiShangYeXian: 0,
          zengJiaoQiang: 0,
          zengShangYeXian: 0,
          xiaoShouChePai: 0,
          zengSongChePai: 0
        }
        this.jiaoDate = {};
        this.getuser();
        this.form.id = "";

      },
      aaa1(a){if(!a){this.form.xiaoShouJinRongMoney = 0}},
      aaa2(a){if(!a){this.form.xiaoShouChePai = 0}},
      aaa3(a){if(!a){this.form.twoCompanyPrice = 0}},
      aaa4(a){if(!a){this.form.zengSongJinRongMoney = 0}},
      aaa5(a){if(!a){this.form.zengSongChePai = 0}},
      aaa6(a){if(!a){this.form.zengJiaoQiang = 0;this.form.zengShangYeXian = 0}},
      aaa7(a){if(!a){this.form.maiJiaoQiang = 0;this.form.maiShangYeXian = 0}},
      save() {
        if (this.jiaoDate.jiaoDate === '' || this.jiaoDate.jiaoDate === null) {
          this.jiaoDate = {};
        }
        this.$ajax.post('carsOrder/save', Object.assign({}, this.form, this.jiaoDate)).then(res => {
          var result = res.data;
          if (result.success) {
            this.$notify({
              title: '提示',
              message: '数据保存成功',
              type: 'success',
              position: 'bottom-right'
            });
            this.form = {
              maiChePai: '',
              zengChePai: '',
              customerName: '',
              idCard: '',
              customerSex: '',
              area: '',
              phone: '',
              customerZhiwei: '',
              dept: '',
              zhiwei: '',
              name: '',
              zhuanjieshao: '',
              dingDate: '',
              cars: '',
              contractNO: '',
              color: '',
              heGeZhengNum: '',
              faPiaoNum: '',
              faDongJi: '',
              cheJia: '',
              xiaoShouPrice: '',
              zengJingPin: '',
              zengBaoYang: '',
              zengYanBao: '',
              zengXiMei: '',
              zengJinRong: '',
              zengSongJinRongMoney: 0,
              maiJingPin: '',
              maiBaoYang: '',
              maiYanBao: '',
              maiXiMei: '',
              maiJinRong: '',
              xiaoShouJinRongMoney: 0,
              twoCompanyName: '',
              twoCompanyPrice: 0,
              maiJiaoQiang: 0,
              maiShangYeXian: 0,
              zengJiaoQiang: 0,
              zengShangYeXian: 0,
              xiaoShouChePai: 0,
              zengSongChePai: 0
            }
            this.jiaoDate = {};
            this.getuser();
          } else {
            this.$notify({
              title: '提示',
              message: result.msg,
              type: 'error',
              position: 'bottom-right'
            });
          }

        })
      },
      //电话查询
      phonecx() {
        if (this.form.phone) {
          this.$ajax.post("carsOrder/xiuPhone", {
            phone: this.form.phone
          }).then(res => {
            var result = res.data;
            if (result.success) {
              this.form = result.data.carsorder;
              if(result.data.zengBaoXianId!=''){this.$set(this.form, "maiChePai", parseInt(result.data.maiChePaiId));}
              if(result.data.zengBaoXianId!=''){this.$set(this.form, "zengChePai", parseInt(result.data.zengChePaiId));}
              this.$set(this.form, "cheJia", result.data.cheJia);
              this.$set(this.form, "color", result.data.color);
              this.$set(this.form, "contractNO", result.data.contractNO);
              this.$set(this.form, "dingDate", new Date(result.data.dingDate));
              this.$set(this.jiaoDate, "jiaoDate", new Date(result.data.jiaoDate));
              this.$set(this.form, "faDongJi", result.data.faDongJi);
              this.$set(this.form, "faPiaoNum", result.data.faPiaoNum);
              this.$set(this.form, "heGeZhengNum", result.data.heGeZhengNum);
              this.$set(this.form, "xiaoShouPrice", result.data.xiaoShouPrice);
              this.$set(this.form, "zhuanjieshao", result.data.zhuanjieshao);
              this.$set(this.form, "cars", parseInt(result.data.carsId));
              this.$set(this.form, "maiJiaoQiang", result.data.maiJiaoQiang);
              this.$set(this.form, "maiShangYeXian", result.data.maiShangYeXian);
              this.$set(this.form, "zengJiaoQiang", result.data.zengJiaoQiang);
              this.$set(this.form, "zengShangYeXian", result.data.zengShangYeXian);
              this.$set(this.form, "twoCompanyPrice", result.data.twoCompanyPrice);
              this.$set(this.form, "xiaoShouJinRongMoney", result.data.xiaoShouJinRongMoney);
              this.$set(this.form, "zengSongJinRongMoney", result.data.zengSongJinRongMoney);
              if(result.data.zengBaoXianId!=''){this.$set(this.form, "maiBaoXian", parseInt(result.data.maiBaoXianId));}
              if(result.data.zengBaoXianId!=''){this.$set(this.form, "zengBaoXian", parseInt(result.data.zengBaoXianId));}
              if(result.data.zengBaoXianId!=''){this.$set(this.form, 'zengJinRong', parseInt(result.data.zengJinRongId));}
              if(result.data.zengBaoXianId!=''){this.$set(this.form, 'maiJinRong', parseInt(result.data.maiJinRongId));}
              this.$set(this.form, "twoCompanyName", result.data.twoCompanyName);
              this.$set(this.form, "xiaoShouChePai", parseInt(result.data.xiaoShouChePai));
              this.$set(this.form, "zengSongChePai", parseInt(result.data.zengSongChePai));
              this.form.id = result.data.carsorderId;
              this.getuser();

              if (result.data.zengJingPinId) {
                var roles = result.data.zengJingPinId.split(',').map(Number)
                var roles1 = []
                for (var arrInt in roles) {
                  roles1.push(roles[arrInt])
                }
                this.$set(this.form, 'zengJingPin', roles1);
              }


              if (result.data.zengBaoYangId) {
                var roles = result.data.zengBaoYangId.split(',').map(Number)
                var roles1 = []
                for (var arrInt in roles) {
                  roles1.push(roles[arrInt])
                }
                this.$set(this.form, 'zengBaoYang', roles1);
              }

              if (result.data.zengYanBaoId) {
                var roles = result.data.zengYanBaoId.split(',').map(Number)
                var roles1 = []
                for (var arrInt in roles) {
                  roles1.push(roles[arrInt])
                }
                this.$set(this.form, 'zengYanBao', roles1);
              }

              if (result.data.zengXiMeiId) {
                var roles = result.data.zengXiMeiId.split(',').map(Number)
                var roles1 = []
                for (var arrInt in roles) {
                  roles1.push(roles[arrInt])
                }
                this.$set(this.form, 'zengXiMei', roles1);
              }


              if (result.data.maiJingPinId) {
                var roles = result.data.maiJingPinId.split(',').map(Number)
                var roles1 = []
                for (var arrInt in roles) {
                  roles1.push(roles[arrInt])
                }
                this.$set(this.form, 'maiJingPin', roles1);
              }

              if (result.data.maiBaoYangId) {
                var roles = result.data.maiBaoYangId.split(',').map(Number)
                var roles1 = []
                for (var arrInt in roles) {
                  roles1.push(roles[arrInt])
                }
                this.$set(this.form, 'maiBaoYang', roles1);
              }

              if (result.data.maiYanBaoId) {
                var roles = result.data.maiYanBaoId.split(',').map(Number)
                var roles1 = []
                for (var arrInt in roles) {
                  roles1.push(roles[arrInt])
                }
                this.$set(this.form, 'maiYanBao', roles1);
              }

              if (result.data.maiXiMeiId) {
                var roles = result.data.maiXiMeiId.split(',').map(Number)
                var roles1 = []
                for (var arrInt in roles) {
                  roles1.push(roles[arrInt])
                }
                this.$set(this.form, 'maiXiMei', roles1);
              }

            } else {
              this.phoneAdd()
            }
          })



        }
      },


      phoneAdd() {
        this.$ajax.post("carsOrder/phone", {
          phone: this.form.phone
        }).then(res => {
          var result = res.data;
          if (result.success) {
            this.form = result.data;
            this.form.cars = "";
            this.$set(this.form, "customerName", result.data.thread.customerName);
            this.$set(this.form, "name", result.data.thread.name);
            if (result.data.huoKeTuJing === null) {
              this.$set(this.form, "zhuanjieshao", "")
            } else if (result.data.huoKeTuJing === "转介绍") {
              this.$set(this.form, "zhuanjieshao", "是")
            } else {
              this.$set(this.form, "zhuanjieshao", "否")
            }
            this.getuser();
            this.form.id = "";
            this.form.zengSongBaoXianMoney = 0;
            this.form.zengSongJinRongMoney = 0;
            this.form.xiaoShouBaoXianMoney = 0;
            this.form.xiaoShouJinRongMoney = 0;
            this.form.maiJiaoQiang = 0,
              this.form.maiShangYeXian = 0,
              this.form.zengJiaoQiang = 0,
              this.form.zengShangYeXian = 0
          }
        })
      },




      jiaoDateChange() {
        if (!(this.form.dingDate)) {
          this.$set(this.form, "dingDate", this.jiaoDate.jiaoDate);
        }
      },
      getuser() { //得到员工信息
        this.$ajax.post('user/getuser', {}).then(res => {
          var result = res.data
          this.$set(this.form, "dept", result.data.deptName)
          this.$set(this.form, "zhiwei", result.data.zhiwei.name)
          this.$set(this.form, "name", result.data.name)
          if("二手车部"===result.data.deptName){
            this.ershou=true
          }
        })
      },
      getCar() { //获取车型
        this.$ajax.post('carsOrder/carType', {}).then(res => {
          var result = res.data
          this.$set(this, "cars", result.data)
          this.showTree = false
          this.$nextTick(() => {
            this.showTree = true;
          });
        })

      },
      getSaleBoutique() { //获取精品
        this.$ajax.post('saleBoutique/list', {}).then(res => {
          var result = res.data
          this.$set(this, "zengJingPin1", result.data)
          this.showTree = false
          this.$nextTick(() => {
            this.showTree = true;
          });
        })

      },
      getSaleCarKeep() { //获得保养
        this.$ajax.post('CarKeep/list', {}).then(res => {
          var result = res.data
          this.$set(this, "zengBaoYang1", result.data)
          this.showTree = false
          this.$nextTick(() => {
            this.showTree = true;
          });
        })
      },
      getSaleYanBao() { //获得延保
        this.$ajax.post('yanbao2/list', {}).then(res => {
          var result = res.data
          this.$set(this, "zengYanBao1", result.data)
          this.showTree = false
          this.$nextTick(() => {
            this.showTree = true;
          });
        })
      },
      getXiMei() { //获得洗美
        this.$ajax.post('ximei2/list', {}).then(res => {
          var result = res.data
          this.$set(this, "zengXiMei1", result.data)
          this.showTree = false
          this.$nextTick(() => {
            this.showTree = true;
          });
        })
      },
      getMoneycompany() { //获得金融
        this.$ajax.post('moneycompany2/list', {}).then(res => {
          var result = res.data
          this.$set(this, "zengJinRong1", result.data)
          this.showTree = false
          this.$nextTick(() => {
            this.showTree = true;
          });
        })
      },
      getCarNumber() { //获得车牌公司
        this.$ajax.post('CarNumberCompany/list', {}).then(res => {
          var result = res.data
          this.$set(this, "zengChePai", result.data)
          this.showTree = false
          this.$nextTick(() => {
            this.showTree = true;
          });
        })
      },
      phoneClear() {
        this.form.id = "";
      },
      getBaoXian() { //获得保险
        this.$ajax.post('Insurance2/list', {}).then(res => {
          var result = res.data
          this.$set(this, "zengBaoXian1", result.data)
          this.showTree = false
          this.$nextTick(() => {
            this.showTree = true;
          });
        })
      },
      getErShouChe() { //获得二手车
        this.$ajax.post('TwoCompany2/list', {}).then(res => {
          var result = res.data
          this.$set(this, "twoCompanyName1", result.data)
          this.showTree = false
          this.$nextTick(() => {
            this.showTree = true;
          });
        })
      },
      shuaxin() {
        this.getuser();
        this.getCar();
        this.getSaleBoutique();
        this.getSaleCarKeep();
        this.getSaleYanBao();
        this.getXiMei();
        this.getMoneycompany();
        this.getBaoXian();
        this.getErShouChe();
        this.getCarNumber();
      },
    },

    created() {
      this.shuaxin();

    }
  }

  function emptyObj(obj) {

    for (var key in obj) {
      var o = obj[key];
      if (o instanceof Object) {
        emptyObj(o);
      } else {
        obj[key] = '';
      }
    }
  }
</script>

<style scoped>
  .el-date-editor.el-input,
  .el-date-editor.el-input__inner {
    width: 215px;
  }

  element.style {
    width: 95px;
  }
</style>
